package com.jd.user.controller;

import com.jd.basic.utils.AjaxResult;
import com.jd.user.dto.UserLoginDto;
import com.jd.user.dto.WechatBinderDto;
import com.jd.user.dto.WechatDto;
import com.jd.user.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 小林同学
 * @version 1.0
 * @description: TODO
 * @date 2023/3/7 15:05
 */
@RestController
@RequestMapping("/login")
public class LoginController {
    @Autowired
    private LoginService loginService;

    @PostMapping("/account")
    public AjaxResult userLogin(@RequestBody @Validated UserLoginDto dto) throws Exception {
        return loginService.userLogin(dto);
    }

    /**
     * 获取WeChat接口的token和openid
     * @author kabuda
     * @date 2023/3/8 10:12
     * @return AjaxResult
    */

    @PostMapping("/wechat")
    public AjaxResult getWechatToken(@RequestBody @Validated WechatDto dto) throws Exception {
        return loginService.getWechatToken(dto);
    }

    @PostMapping("/wechat/binder")
    public AjaxResult binding(@RequestBody @Validated WechatBinderDto dto) throws Exception {
        return loginService.binding(dto);
    }
}
